﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
    var commentUrl = path + "ReplyServlet?method=addReply";
	var userId="${userid}";//获取EL表达式中的值
	var infoId="${form.id}";//帖子的id
	var uid="${form.uid}";//发帖人的id
	var readnum="${form.readnum-1}";//该帖子的阅读量
	var path = "<c:url value='/'/>";
	
	var title="${form.title}";//文章的标题
	var message="${form.message}";//文章的正文
	
	//创建异步对象
	function createXMLHttpRequest() {
		try {
			return new XMLHttpRequest();//大多数浏览器
		} catch (e) {
			try {
				return ActvieXObject("Msxml2.XMLHTTP");//IE6.0
			} catch (e) {
				try {
					return ActvieXObject("Microsoft.XMLHTTP");//IE5.5及更早版本	
				} catch (e) {
					alert("哥们儿，您用的是什么浏览器啊？");
					throw e;
				}
			}
		}
	}
	
	function a1()
	{
		
		//获取评论内容
		var comment = document.getElementById("liuyan").value;
		//判断
		if(comment.length==0){
			alert("评论内容不能为空！");
			return ;
		}
		
		//1，得到异步对象
		var xmlHttp = createXMLHttpRequest();
		//2，打开连接,传参，请求的路径
		xmlHttp.open("POST","<c:url value='/ForwardServlet'/>",true);
		
		//3，设置请求头
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		
		//4，发送请求，给出请求体
		comment=window.encodeURIComponent(comment); //解析特殊字符，防止后台无法解析
		var parameter ="aid="+infoId+ "&userid="+userId+ "&message=" + comment;
		xmlHttp.send(parameter);
		//5，给xmlHttp的onreadystatechange事件注册监听
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {//双重判断
				alert("哇哇哇");
				//获取服务器的响应，判断是否为1
				//是，获取span，添加内容:“用户名已被注册”
				var response = xmlHttp.responseText;//跟servlet的response.getWriter().print("1");相对应			
				if(response==0){//未登录
					window.location = path+"jsps/user/log.jsp";
				}else if(response==1){
					alert("评论成功！等待审核");
					window.location = path+"ArticleServlet1?method=findById&id="+infoId+"&readnum="+readnum;
				}else{
					alert("评论失败！");
				}
			}
		};
		
	}
	
	function b()
	{
		
	}
	
	function c()
	{
		
	}
</script>


<script src='<c:url value="/jsps/user/js/jquery-3.1.0.js"></c:url>' type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src='<c:url value="/jsps/article/js/article.js"></c:url>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/jsps/article/css/article.css"></c:url>' />
</head>
<body>
	<!-- 导入头 -->
	<jsp:include page="/userLog.jsp" flush="true"/>
	
	<br />
	<br />
	<div class="title">
		${form.title} <br /> <span class="titlespan">
			——作者:${form.username}&nbsp;&nbsp;发表时间：${time1}&nbsp;&nbsp;阅读量：${form.readnum}
		</span>
	</div>
	<br />
	<br />
	<br />
	<div class="message">${form.message}</div>
	<br />
	
	
	<div>
	<form action="" method="post">
		我要评论:<br />
		<textarea name="liuyan" id="liuyan"></textarea>
		<!-- <input type="submit" name="submit" onclick="a1()" value="评论测试"/> -->
		<button id="a" name="reply">评论</button>
		<button id="forward" name="forward">转发</button>
	</form>
	</div>
	
<!-- 导入尾 -->	
     <jsp:include page="/jsps/article/tail.jsp" flush="true" />
			
</body>
</html>
